]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
messageTray: Hook SourceActor up to source icon changes automatically
authorJasper St. Pierre <jstpierre@mecheye.net>
Mon, 23 Jul 2012 04:07:51 +0000 (01:07 -0300)
committerGiovanni Campagna <gcampagna@src.gnome.org>
Fri, 17 Aug 2012 22:36:13 +0000 (00:36 +0200)
Instead of manually tracking source icon changes, or requiring a manual
call to _setSummaryIcon, add a way to emit a signal when we're guaranteed
the icon has been changed, and then the source actor will automatically
update the icon.
_setSummaryIcon is still available for sources such as the notification
daemon, that require special treatment for the summary icon (to be used
with tray icons)

https://bugzilla.gnome.org/show_bug.cgi?id=680426

js/ui/messageTray.js
js/ui/notificationDaemon.js
js/ui/screenShield.js
js/ui/telepathyClient.js

index 2a736b68b47daa4723d28f350c0b0496ecb27b19..e135506a57a3f6b7d667dc2d9a69bab5acca910c 100644 (file)
@@ -1042,6 +1042,7 @@ const SourceActor = new Lang.Class({
 
     _init: function(source, size) {
         this._source = source;
+        this._size = size;
 
         this.actor = new Shell.GenericContainer();
         this.actor.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
@@ -1067,10 +1068,14 @@ const SourceActor = new Lang.Class({
 
         this._source.connect('count-updated', Lang.bind(this, this._updateCount));
         this._updateCount();
+
+        this._source.connect('icon-updated', Lang.bind(this, this._updateIcon));
+        this._updateIcon();
     },
 
     setIcon: function(icon) {
         this._iconBin.child = icon;
+        this._iconSet = true;
     },
 
     _getPreferredWidth: function (actor, forHeight, alloc) {
@@ -1108,13 +1113,21 @@ const SourceActor = new Lang.Class({
         this._counterBin.allocate(childBox, flags);
     },
 
+    _updateIcon: function() {
+        if (this._actorDestroyed)
+            return;
+
+        if (!this._iconSet)
+            this._iconBin.child = this._source.createIcon(this._size);
+    },
+
     _updateCount: function() {
         if (this._actorDestroyed)
             return;
 
         this._counterBin.visible = this._source.countVisible;
         this._counterLabel.set_text(this._source.count.toString());
-    },
+    }
 });
 
 const Source = new Lang.Class({
@@ -1175,16 +1188,12 @@ const Source = new Lang.Class({
                              icon_size: size });
     },
 
-    _ensureMainIcon: function(icon) {
+    _ensureMainIcon: function() {
         if (this._mainIcon)
-            return false;
-
-        if (!icon)
-            icon = this.createIcon(this.ICON_SIZE);
+            return;
 
         this._mainIcon = new SourceActor(this, this.ICON_SIZE);
-        this._mainIcon.setIcon(icon);
-        return true;
+        return;
     },
 
     // Unlike createIcon, this always returns the same actor;
@@ -1236,10 +1245,15 @@ const Source = new Lang.Class({
         return false;
     },
 
+    iconUpdated: function() {
+        this.emit('icon-updated');
+    },
+
     //// Protected methods ////
     _setSummaryIcon: function(icon) {
-        if (!this._ensureMainIcon(icon))
-            this._mainIcon.setIcon(icon);
+        this._ensureMainIcon();
+        this._mainIcon.setIcon(icon);
+        this.iconUpdated();
     },
 
     open: function(notification) {
index 0eee59b87ec57b438b3b74470dfa05c3a3da72b6..6b1d80be87ff05b3255f7bcbdf578974c587e171 100644 (file)
@@ -557,7 +557,8 @@ const Source = new Lang.Class({
     processNotification: function(notification, gicon) {
         if (gicon)
             this._gicon = gicon;
-        this._setSummaryIcon(this.createIcon(this.ICON_SIZE));
+        if (!this.trayIcon)
+            this.iconUpdated();
 
         let tracker = Shell.WindowTracker.get_default();
         if (notification.resident && this.app && tracker.focus_app == this.app)
@@ -625,7 +626,7 @@ const Source = new Lang.Class({
         // notification-based icons (ie, not a trayicon) or if it was unset before
         if (!this.trayIcon) {
             this.useNotificationIcon = false;
-            this._setSummaryIcon(this.createIcon(this.ICON_SIZE));
+            this.iconUpdated();
         }
     },
 
index abd68bd706e81cef116e15d76ec4d0a233784305..e82386314a0aad7f081d7910cd29c64744bdea0c 100644 (file)
@@ -140,9 +140,7 @@ const NotificationsBox = new Lang.Class({
     _makeNotificationSource: function(source) {
         let box = new St.BoxLayout({ style_class: 'screen-shield-notification-source' });
 
-        let iconClone = source.createIcon(SUMMARY_ICON_SIZE);
         let sourceActor = new MessageTray.SourceActor(source, SUMMARY_ICON_SIZE);
-        sourceActor.setIcon(iconClone);
         box.add(sourceActor.actor, { y_fill: true });
 
         let textBox = new St.BoxLayout({ vertical: true });
index 0ea8e7f9c2771b1b6c7c844bb918da82379822ad..ffa84dd44d9510bc46e4bb75ec8614dcada9f4e3 100644 (file)
@@ -536,7 +536,7 @@ const ChatSource = new Lang.Class({
     },
 
     _updateAvatarIcon: function() {
-        this._setSummaryIcon(this.createIcon(this.ICON_SIZE));
+        this.iconUpdated();
         this._notification.update(this._notification.title, null, { customContent: true });
     },